/*
 * TripServlet.java
 *
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.fpdev.apps.web.servlets;

import java.io.*;
import java.rmi.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.*;
import javax.servlet.http.*;

import org.fpdev.apps.web.*;

public class TripServlet extends FPServlet {

  @Override
  public void doGet(HttpServletRequest request, HttpServletResponse response)
          throws IOException, ServletException {
    count_++;
    String sessID = request.getSession().getId();
    Logger qlog = getQueryLogger();
    qlog.log(Level.INFO, "TS c=" + count_ + " sess=" + sessID + "::doGet entered");

    response.setContentType("text/xml");
    PrintWriter out = response.getWriter();

    int triptype = new Integer(request.getParameter("triptype")).intValue();
    String start = request.getParameter("start");
    String end = request.getParameter("end");
    int hour = new Integer(request.getParameter("hour")).intValue();
    int min = new Integer(request.getParameter("min")).intValue();
    int ampm = new Integer(request.getParameter("ampm")).intValue();
    String dayStr = request.getParameter("day");
    String deparrStr = request.getParameter("deparr");
    String optmodeStr = request.getParameter("optmode");
    double nmspeed = new Double(request.getParameter("nmspeed")).doubleValue();
    double nmradius = new Double(request.getParameter("nmradius")).doubleValue();
    double typefact = new Double(request.getParameter("typefact")).doubleValue();
    double topfact = new Double(request.getParameter("topfact")).doubleValue();
    short scenID = (request.getParameter("scenid") == null) ? 1 : new Short(request.getParameter("scenid")).shortValue();

    //out.println("Start: "+start+"<br/>");
    //out.println("End: "+end+"<br/>");
    //out.println("Time: "+hour+":"+min+" "+ampm+"<br/>");
    try {
      out.println(server_.planTrip(scenID, triptype, start, end, hour, min, ampm, dayStr, deparrStr, optmodeStr, nmspeed, nmradius, typefact, topfact));

      qlog.log(Level.INFO, "TS c=" + count_ + " sess=" + sessID + "::doGet completed");

    } catch (Exception e) {
      out.println("exception: " + e);
    }

  //out.println("</body>");
  //out.println("</html>");
  }

  public void doPost(HttpServletRequest request,
          HttpServletResponse response)
          throws ServletException, IOException {
    doGet(request, response);
  }

  @Override
  protected String getLoggerCode() {
    return "trip";
  }
}



























